package com.kingbook.services;

import com.kingbook.common.utils.DateUtils;
import com.kingbook.common.utils.StringUtils;
import com.kingbook.core.base.SupportService;
import com.kingbook.core.result.JSONResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import static com.kingbook.common.enums.DateFormatEnum.YEAR_MONTH;

/**
 * @Author Bucky
 * @Date 2020-03-30 21:25:05
 * @Version 1.0
 */
@Slf4j
@Service
public class SpendService extends SupportService {

    @PostConstruct
    private void init() {
        setNamespace("Spend");
    }

    public String expendMonth(int mid) {
        Map<String, Object> param = new HashMap<>(3);
        String month = DateUtils.format(new Date(), YEAR_MONTH);
        param.put("mid", mid);
        param.put("startDate", month + "-01");
        param.put("endDate", month + "-31");
        JSONResult re = query("queryExpendMonth", param);
        String e = "0";
        if (re.isSuccess() && re.getCount() > 0) {
            e = re.getDataElement("totalAmount");
        }
        return StringUtils.isEmpty(e) ? "0" : e;
    }
}
